<!DOCTYPE html>
<html>
<head>
<#include "/admin/common/common.ftl" parse=true encoding="utf-8">
<link href="${base}/scripts/ckeditor/skins/moono/editor.css" type="text/css" rel="stylesheet">
</head>
<body class="hold-transition skin-blue sidebar-mini">
	<div class="wrapper">

		<#include "/admin/common/header.ftl" parse=true encoding="utf-8">


		<!-- Content Wrapper. Contains page content -->
		<div class="content-wrapper">
			<!-- Content Header (Page header) -->
			<section class="content-header">
				<h1>模板管理</h1>
				<ol class="breadcrumb">
					<li class="active">修改邮件模板</li>
				</ol>
			</section>

			<!-- Main content -->
			<section class="content">
				<!-- Info boxes -->
				<div class="row">
					<div class="box">
						<div class="box-header">
							<div class="table-btn">
								<a href="${base}/admin/template/mail/addnew.do">
									<span class="label label-primary">新增</span>
								</a>
								<a href="${base}/admin/template/mail/list.do">
									<span class="label label-primary">列表</span>
								</a>
							</div>
						</div>
						<!-- /.box-header -->
						<div class="box-body">
							<h3 id="affix-events">修改邮件模板信息</h3>
							<form class="form-horizontal" role="form" id="defaultForm" method="post">
								<input type="hidden" id="id" name="id" value="${entity.id!}">
								<input type="hidden" id="typeIndex" name="typeIndex" value="${entity.typeIndex!}">
								<div class="form-group">
									<label class="col-md-2 control-label">模板类型</label>
									<div class="col-md-8">
										<select id="type" name="type">
											<option value="1">邮箱验证模板</option>
											<option value="2">验证码模板</option>
											<option value="3">找回密码模板</option>
											<option value="4">修改密码模板</option>
											<option value="5">修改邮箱模板</option>
											<option value="6">警告邮件模板</option>
											<option value="99">其他模板</option>
										</select>
									</div>
								</div>
								<div class="form-group">
									<label class="col-md-2 control-label">模板名称</label>
									<div class="col-md-8">
										<input id="name" name="name" class="form-control" type="text" rows="10" value="${entity.name}">
									</div>
								</div>
								<div class="form-group">
									<label class="col-md-2 control-label">模板描述</label>
									<div class="col-md-8">
										<textarea class="form-control" rows="8" id="describe" placeholder="请输入模板描述" name="describe">${entity.describe!}</textarea>
									</div>
								</div>
								<div class="form-group">
									<label class="col-md-2 control-label">默认模板</label>
									<div class="col-md-8">
										<input type="radio" name="isDefault" value="true" checked="checked">
										是
										<input type="radio" name="isDefault" value="false">
										否
									</div>
								</div>
								<div class="form-group">
									<label class="col-md-2 control-label">邮件主题</label>
									<div class="col-md-8">
										<input id="subject" name="subject" class="form-control" type="text" rows="10" value="${entity.subject!}">
									</div>
								</div>
								<div class="form-group">
									<label class="col-md-2 control-label">邮件内容</label>
									<div class="col-md-8">
										<textarea class="form-control" rows="8" id="content" placeholder="请输入模板内容" name="content">${entity.content!}</textarea>
									</div>
								</div>
								<div class="form-group">
									<div class="col-sm-offset-3 col-sm-3">
										<button type="submit" class="btn btn-primary">修改</button>
									</div>
								</div>
							</form>
						</div>
						<!-- /.box-body -->
					</div>
					<!-- /.box -->
				</div>
				<!-- /.row -->
			</section>
			<!-- /.content -->
		</div>
		<!-- /.content-wrapper -->

		<#include "/common/footer.ftl" parse=true encoding="utf-8">

	</div>
	<!-- ./wrapper -->
	<script src="${base}/scripts/ckeditor/ckeditor.js"></script>
	<script src="${base}/scripts/ckeditor/config.js"></script>
	<script src="${base}/scripts/ckeditor/styles.js"></script>
	<script src="${base}/scripts/ckeditor/lang/zh-cn.js"></script>
	<script type="text/javascript">
		$(function() {
			var contentEditor = null;
			contentEditor = CKEDITOR.replace('content');
			
			<#if entity.type??>
			$("#type").val("${entity.typeIndex!}");
			</#if>
			<#if entity.isDefault??>
			<#if entity.isDefault=="是">
			$("input[name='isDefault'][value='true']").attr("checked",true);
			<#else>
			$("input[name='isDefault'][value='false']").attr("checked",true);
			</#if>
			</#if>
			
			$('#defaultForm').bootstrapValidator({
				message : '该项不能为空',
				live : 'disabled',
				feedbackIcons : {
					valid : 'glyphicon glyphicon-ok',
					invalid : 'glyphicon glyphicon-remove',
					validating : 'glyphicon glyphicon-refresh'
				},
				submitHandler : function(validator, form, submitButton) {
					 if (window.confirm("确定要修改该邮件模板吗？")) {
						 	contentEditor.updateElement();
							var url = "${base}/admin/template/mail/modifyAction.json";
							var entity = {
									id:$("#id").val(),
									type: $("#type").val(),
								 	name: $("#name").val(),
									describe:$("#describe").val(),
									isDefault:$("input[name='isDefault']:checked").val(),
									subject:$("#subject").val(),
									content:$("#content").val()
							};
							var onloadFunc = function(result) {
								if (result.isSuccess == true) {
									window.location = "${base}/admin/template/mail/list.do";
								} else {
									alert(result.message);
								}
							};
							httpRequestPostJson(url, entity, false, onloadFunc); 
						} else{
							return;
						} 
				},
				fields : {
					name : {
						validators : {
							notEmpty : {
								message : '模板名称不能为空'
							}
						}
					},
					describe : {
						validators : {
							notEmpty : {
								message : '模板描述不能为空'
							}
						}
					},
					subject:{
						validators:{
							notEmpty:{
								message:'邮件主题不能为空'
							}
						}
					},
					content : {
						validators : {
							notEmpty : {
								message : '模板内容不能为空'
							}
						}
					}
				}
			});
		});
	</script>
</body>
</html>

